/**
 * @author wangjing
 * @ZephyrSkyline
 * @version 创建时间：2013-12-3 下午12:17:33
 */

package com.lc.sms;

import java.util.Random;

public class CharSequenceBuilder {
	/*
	 * 根据指定长度生成字母和数字的随机数 0~9的ASCII为48~57 A~Z的ASCII为65~90 a~z的ASCII为97~122
	 */
	public static String createRandomCharSEQ(int length) {
		if (length <= 0) {
			return null;
		}
		StringBuilder sb = new StringBuilder();
		Random randIndex = new Random();
		Random randData = new Random();
		int data = 0;
		for (int i = 0; i < length; i++) {
			int index = randIndex.nextInt(3); // 生成三种情况 1. 0-9 2. A-Z 3. a-z
			switch (index) {
			case 0:
				data = randData.nextInt(10);// 仅仅会生成0~9
				sb.append(data);
				break;
			case 1:
				data = randData.nextInt(26) + 65;// 保证只会产生65~90之间的整数
				sb.append((char) data);
				break;
			case 2:
				data = randData.nextInt(26) + 97;// 保证只会产生97~122之间的整数
				sb.append((char) data);
				break;
			}
		}
		String result = sb.toString();
		return result;
	}
	public static String createRandomNumberSEQ(int length) {
		if (length <= 0) {
			return null;
		}
		StringBuilder sb = new StringBuilder();
		Random rand = new Random();
		for (int i = 0; i < length; i++) {
			sb.append(rand.nextInt(10)); //仅仅会生成0~9
		}
		String result = sb.toString();
		return result;
	}
}
